{% extends "base.html" %}

{% block title %}{% if is_edit %}编辑课程{% else %}添加课程{% endif %}{% endblock %}

{% block content %}
<div class="container">
    <div class="row justify-content-center">
        <div class="col-md-6">
            <div class="card">
                <div class="card-header bg-primary text-white">
                    <h3 class="card-title mb-0">{% if is_edit %}编辑课程{% else %}添加课程{% endif %}</h3>
                </div>
                <div class="card-body">
                    <form method="POST" action="{{ url_for('edit_course', id=course.id) if is_edit else url_for('add_course') }}">
                        {{ form.hidden_tag() }}
                        
                        <!-- 课程编号 -->
                        <div class="form-group">
                            {{ form.course_id.label(class="form-label") }}
                            {% if form.course_id.errors %}
                                {{ form.course_id(class="form-control is-invalid") }}
                                <div class="invalid-feedback">
                                    {% for error in form.course_id.errors %}
                                        <span>{{ error }}</span>
                                    {% endfor %}
                                </div>
                            {% else %}
                                {{ form.course_id(class="form-control", placeholder="请输入课程编号") }}
                            {% endif %}
                        </div>
                        
                        <!-- 课程名称 -->
                        <div class="form-group">
                            {{ form.name.label(class="form-label") }}
                            {% if form.name.errors %}
                                {{ form.name(class="form-control is-invalid") }}
                                <div class="invalid-feedback">
                                    {% for error in form.name.errors %}
                                        <span>{{ error }}</span>
                                    {% endfor %}
                                </div>
                            {% else %}
                                {{ form.name(class="form-control", placeholder="请输入课程名称") }}
                            {% endif %}
                        </div>
                        
                        <!-- 学分 -->
                        <div class="form-group">
                            {{ form.credit.label(class="form-label") }}
                            {% if form.credit.errors %}
                                {{ form.credit(class="form-control is-invalid") }}
                                <div class="invalid-feedback">
                                    {% for error in form.credit.errors %}
                                        <span>{{ error }}</span>
                                    {% endfor %}
                                </div>
                            {% else %}
                                {{ form.credit(class="form-control", placeholder="请输入学分") }}
                            {% endif %}
                        </div>
                        
                        <!-- 授课教师 -->
                        <div class="form-group">
                            {{ form.teacher.label(class="form-label") }}
                            {% if form.teacher.errors %}
                                {{ form.teacher(class="form-control is-invalid") }}
                                <div class="invalid-feedback">
                                    {% for error in form.teacher.errors %}
                                        <span>{{ error }}</span>
                                    {% endfor %}
                                </div>
                            {% else %}
                                {{ form.teacher(class="form-control", placeholder="请输入授课教师") }}
                            {% endif %}
                        </div>
                        
                        <!-- 提交按钮 -->
                        <div class="form-group text-center mt-4">
                            <button type="submit" class="btn btn-primary btn-lg">
                                <i class="fas fa-save me-2"></i>{% if is_edit %}更新课程{% else %}添加课程{% endif %}
                            </button>
                            <a href="{{ url_for('courses') }}" class="btn btn-secondary btn-lg">
                                <i class="fas fa-times me-2"></i>取消
                            </a>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
{% endblock %}